package com.erp.erp_servers.InspectCargo.imp;

import com.erp.erp_dao.InspectCargo.IInspectCargoProductDAO;
import com.erp.erp_entitys.InspectCargo.*;
import com.erp.erp_servers.InspectCargo.IInspectCargoProductService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.List;

@Service
public class ImpInspectCargoProductService implements IInspectCargoProductService {
    @Autowired
    private IInspectCargoProductDAO inspectCargoProductDAO;

    @Override
    public int deleteByPrimaryKey(Integer id) {
        return inspectCargoProductDAO.deleteByPrimaryKey(id);
    }

    @Override
    public int insert(InspectCargoProductEntity record) {
        return inspectCargoProductDAO.insert(record);
    }

    @Override
    public int insertSelective(InspectCargoProductEntity record) {
        return inspectCargoProductDAO.insertSelective(record);
    }

    @Override
    public InspectCargoProductEntity selectByPrimaryKey(Integer id) {
        return inspectCargoProductDAO.selectByPrimaryKey(id);
    }

    @Override
    public int updateByPrimaryKeySelective(InspectCargoProductEntity record) {
        return inspectCargoProductDAO.updateByPrimaryKeySelective(record);
    }

    @Override
    public int updateByPrimaryKey(InspectCargoProductEntity record) {
        return inspectCargoProductDAO.updateByPrimaryKey(record);
    }

    @Override
    public List<InspectCargoProductEntity> selectProductByIcId(Integer icId) {
        return inspectCargoProductDAO.selectProductByIcId(icId);
    }

    @Override
    public PageInfo<CarryPlanVo> selectCarryPlanList(CarryPlanVo vo) {
        List<CarryPlanVo> carryPlanList = inspectCargoProductDAO.selectCarryPlanList(vo);
        PageInfo pageInfo = new PageInfo(carryPlanList);
        if(!CollectionUtils.isEmpty(carryPlanList)){
            pageInfo.setList(carryPlanList);
            return pageInfo;
        }
        return pageInfo;
    }

    @Override
    public PageInfo<InspectCargoProductEntity> selectCarryPlanProductByCpId(Integer cpId) {
        List<InspectCargoProductEntity> carryPlanAndStockProductVos = inspectCargoProductDAO.selectCarryPlanProductByCpId(cpId);
        PageInfo pageInfo = new PageInfo(carryPlanAndStockProductVos);
        if(!CollectionUtils.isEmpty(carryPlanAndStockProductVos)){
            pageInfo.setList(carryPlanAndStockProductVos);
            return pageInfo;
        }
        return pageInfo;
    }

    @Override
    public PageInfo<InspectCargoProductEntity> selectCarryPlanProductByCarryPlanIds(List<Integer> idList) {
        List<InspectCargoProductEntity> carryPlanAndStockProductVos = inspectCargoProductDAO.selectCarryPlanProductByCarryPlanIds(idList);
        PageInfo pageInfo = new PageInfo(carryPlanAndStockProductVos);
        if(!CollectionUtils.isEmpty(carryPlanAndStockProductVos)){
            pageInfo.setList(carryPlanAndStockProductVos);
            return pageInfo;
        }
        return pageInfo;
    }

    @Override
    public PageInfo<StockVo> selectStockList(StockVo vo) {
        List<StockVo> stockList = inspectCargoProductDAO.selectStockList(vo);
        PageInfo pageInfo = new PageInfo(stockList);
        if(!CollectionUtils.isEmpty(stockList)){
            pageInfo.setList(stockList);
            return pageInfo;
        }
        return pageInfo;
    }

    @Override
    public PageInfo<InspectCargoProductEntity> selectStockProductByStockId(Integer stockId) {
        List<InspectCargoProductEntity> stockProductVos = inspectCargoProductDAO.selectStockProductByStockId(stockId);
        PageInfo pageInfo = new PageInfo(stockProductVos);
        if(!CollectionUtils.isEmpty(stockProductVos)){
            pageInfo.setList(stockProductVos);
            return pageInfo;
        }
        return pageInfo;
    }

    @Override
    public PageInfo<InspectCargoProductEntity> selectStockProductByStockIds(List<Integer> idList) {
        List<InspectCargoProductEntity> stockProductVos = inspectCargoProductDAO.selectStockProductByStockIds(idList);
        PageInfo pageInfo = new PageInfo(stockProductVos);
        if(!CollectionUtils.isEmpty(stockProductVos)){
            pageInfo.setList(stockProductVos);
            return pageInfo;
        }
        return pageInfo;
    }

    @Override
    public int generateInspectCargoProductByShipmentPlanId(Integer inspectCargoId, String shipmentNo) {
        return inspectCargoProductDAO.generateInspectCargoProductByShipmentPlanId(inspectCargoId,shipmentNo);
    }
}
